//
//  Cloud_tableViewCellFive.m
//  EggSteward
//
//  Created by 王道林 on 16/9/1.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "Cloud_tableViewCellFive.h"
#import "BaseView.h"
#import "Masonry.h"

@interface Cloud_tableViewCellFive ()<UITextViewDelegate>
@property (nonatomic, strong) BaseView *View;
@end

@implementation Cloud_tableViewCellFive

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubview];
        [self notification];
        [self addGesture];
    }
    return self;
}
- (void)notification
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"day" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dayTime:) name:@"day" object:nil];
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    BOOL is = [userDefault boolForKey:@"night"];
    if (is == NO) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"day" object:nil userInfo:nil];
    }
}
- (void)dayTime:(NSNotification *)sender
{
    self.contentView.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
}

- (void)createSubview
{
    self.contentView.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    // 背景view
    _View = [[BaseView alloc] init];
    _View.backgroundColor = [UIColor whiteColor];
    _View.layer.masksToBounds = YES;
    _View.layer.cornerRadius = 10;
    [self.contentView addSubview:_View];
    // textview
    _textView = [[BaseTextView alloc] init];
    _textView.text = @"临床表现";
    _textView.delegate = self;
    _textView.clearsContextBeforeDrawing = YES;
    [_View addSubview:_textView];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    [_View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).mas_offset(20);
        make.right.mas_equalTo(self.contentView.mas_right).mas_offset(-20);
        make.top.mas_equalTo(self.contentView.mas_top).mas_offset(10);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).mas_offset(-10);
    }];
    [_textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(15);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-15);
        make.top.mas_equalTo(_View.mas_top).mas_offset(15);
        make.bottom.mas_equalTo(_View.mas_bottom).mas_offset(-15);
    }];
}

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    self.blockBegenText();
    
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
    self.blockEndText();
    [textView resignFirstResponder];
}

#pragma mark -添加下滑手势,回收键盘
- (void)addGesture
{
    UISwipeGestureRecognizer *tapGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    tapGesture.direction = UISwipeGestureRecognizerDirectionRight;
    [self.contentView addGestureRecognizer:tapGesture];
}
-(void)tapAction:(UITapGestureRecognizer *)tap
{
    [_textView resignFirstResponder];
}




@end
